package com.zensun.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zensun.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.*;
import java.util.Date;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author gmk
 */
@ApiModel("管理员配置表")
@Data
@TableName("sys_user")
public class SysUser extends BaseEntity<SysUser> {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @ApiModelProperty("用户编号")
    @TableId
    @Null(message = "用户ID必须为空", groups = AddGrop.class)
    @NotNull(message = "用户ID不能为空", groups = UpdateGrop.class)
    private Long userId;

    /**
     * 部门ID
     */
    @ApiModelProperty("部门ID")
    private Long deptId;

    /**
     * 用户姓名
     */
    @ApiModelProperty("用户姓名")
    @NotBlank(message = "用户姓名不能为空", groups = {AddGrop.class, UpdateGrop.class})
    private String userName;

    /**
     * 用户类型（1系统用户  2项目人员）
     */
    @ApiModelProperty(value = "用户类型（1系统用户  2项目人员）", hidden = true)
    private String userType;

    /**
     * 手机号码
     */
    @Pattern(regexp = "^1[3465789]\\d{9}$", message = "输入的手机号码不合法", groups = {AddGrop.class, UpdateGrop.class})
    @NotBlank(message = "手机号不能为空", groups = AddGrop.class)
    @Null(message = "手机号不能修改", groups = UpdateGrop.class)
    @ApiModelProperty("手机号码")
    private String telephone;

    /**
     * 用户性别
     */
    @ApiModelProperty("用户性别")
    private String sex;

    /**
     * 用户头像
     */
    @ApiModelProperty(value = "用户头像", hidden = true)
    private String avatar;

    /**
     * 密码
     */
    @ApiModelProperty("用户密码")
    @NotBlank(message = "用户密码", groups = AddGrop.class)
    @Null(message = "用户密码必须为空", groups = UpdateGrop.class)
    private String password;

    /**
     * 帐号状态（0停用 1正常）
     */
    @ApiModelProperty("帐号状态（0停用 1正常）")
    @NotBlank(message = "帐号状态不能为空", groups = {AddGrop.class, UpdateGrop.class})
    private String status;

    /**
     * 是否删除（0 否 1是）
     */
    @ApiModelProperty(value = "是否删除（0 否 1是）", hidden = true)
    private Integer isDelete;

    /**
     * 最后登录IP
     */
    @ApiModelProperty(value = "最后登录IP", hidden = true)
    private String loginIp;

    /**
     * 最后登录时间
     */
    @ApiModelProperty(value = "最后登录时间", hidden = true)
    private Date loginDate;

    @ApiModelProperty("添加时是否选择新用户")
    @TableField(exist = false)
    private Boolean selectNew;

    /**
     * 部门对象
     */
    @ApiModelProperty(value = "部门对象", hidden = true)
    @TableField(exist = false)
    private SysDept dept;

    /**
     * 角色对象
     */
    @ApiModelProperty(value = "角色对象", hidden = true)
    @TableField(exist = false)
    private List<SysRole> roles;

    /**
     * 角色组
     */
    @ApiModelProperty("用户拥有的角色")
    @Size(min = 1, message = "请选择角色", groups = {AddGrop.class, UpdateGrop.class})
    @NotNull(message = "请选择角色", groups = {AddGrop.class, UpdateGrop.class})
    @TableField(exist = false)
    private Long[] roleIds;


    public SysUser() {

    }

    public SysUser(Long userId) {
        this.userId = userId;
    }
}
